package com.example.community.controller;

import com.example.community.entity.user;
import com.example.community.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class userController {

    @Autowired
    private com.example.community.service.impl.userImpl userImpl;

    @GetMapping("/login/{username}/{password}")
    public Result<user> login(@PathVariable String username,@PathVariable String password){
        user user = userImpl.login(username,password);
        if(user!=null){
            return Result.success(user,"success");
        }else {
            return Result.error("1","账号密码错误");
        }
    }
    @GetMapping("/register/{username}/{password}")
    public Result<user> register(@PathVariable String username,@PathVariable String password){
        System.out.println(username+"和"+password);
        user user = userImpl.register(username,password);
        if(user!=null){
            return Result.success(user,"success");
        }else {
            return Result.error("1","注册失败(用户名重复或者网络异常)");
        }
    }
}
